package com.frejoys.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.frejoys.common.dto.agent.AgentRoleGroupPageDto;
import com.frejoys.common.vo.agent.AgentRoleGroupVo;
import com.frejoys.dao.entity.AgentRoleGroup;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface AgentRoleGroupMapper extends BaseMapper<AgentRoleGroup> {

    //查找父级id层级关系
    @Select("select id,path from j_agent_role_group where id = #{pid}")
    AgentRoleGroup getPidPath(@Param("pid")Integer pid);


    //分页查询代理角色组(父级)
    Page<AgentRoleGroupVo> pageAgentRoleGroup(Page page, @Param("dto") AgentRoleGroupPageDto dto);

    //查询代理角色组
    List<AgentRoleGroupVo> listAgentRoleGroup(@Param("pids") List<Integer> pids);

    //查询代理角色是否已经存在的有组
    @Select("select id from j_agent_role_group where agent_role_id = #{roleId} limit 1")
    Integer getId(@Param("roleId") Integer roleId);

    //查询自己管理的代理角色组
    List<AgentRoleGroupVo> listAgentRoleGroupByUserId(@Param("userId") Long userId);

    //根据名字查询组id
    @Select("select id from j_agent_role_group where name like concat('%',#{name},'%')")
    List<Integer> getNameById(@Param("name") String name);
}
